﻿using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Windows.Application.Share;
using Windows.Assistance.Domain;
using Windows.Assistance.Infrastructure.EFCore;
using Windows.Infrastructure.Share.Extensions;

namespace Windows.Assistance.Application
{
    public class LogSignInService : ILogSignInService
    {
        // private readonly IMapper _mapper;
        private readonly IHttpContextAccessor _context;
        private readonly AssistanceDbContext _db;
        public LogSignInService(IHttpContextAccessor context, AssistanceDbContext db)
        {
            _context = context;
            //_mapper = mapper;
            _db = db;
        }
        /// <summary>
        /// 获取登录日志列表
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public async Task<PageResponse<LogSignInResponse>> Query(PageRequest info)
        {
            PageResponse<LogSignInResponse> model = new PageResponse<LogSignInResponse>();
            var query = _db.LogSignIn.AsNoTracking();
            int totalCount = await query.CountAsync();
            List<LogSignIn> list = await query.Paging(info.PageIndex, info.PageSize).ToListAsync();
            model.PageIndex = info.PageIndex;
            model.PageSize = info.PageSize;
            model.TotalCount = totalCount;
            //model.List = _mapper.Map<List<LogLoginResponse>>(list);
            return model;
        }
    }
}
